﻿using SingleUserMall.Authorization.Users;
using SingleUserMall.Commissions;
using SingleUserMall.EntityFramework;
using SingleUserMall.Points;
using System.Linq;

namespace SingleUserMall.Migrations.SeedData
{
    class DefaultReleasePointRulesCreator
    {
        private readonly SingleUserMallDbContext _context;

        public DefaultReleasePointRulesCreator(SingleUserMallDbContext context)
        {
            _context = context;
        }

        public void Create()
        {
            CreateDefaultPointRules();
        }

        private void CreateDefaultPointRules()
        {
            User adminUser = _context.Users.FirstOrDefault(u => u.UserName == User.AdminUserName);
            if (adminUser != null)
            {
                //Default sms count
                var count = _context.ReleasePointRules.Count();
                if (count == 0)
                {
                    _context.ReleasePointRules.Add(new ReleasePointRules
                    {
                        Name = "默认体验金释放规则",
                        NormalUserOwnBuyRate = 0.02,
                        VIPUserOwnBuyRate = 0.06,
                        SuperVIPUserOwnBuyRate = 0.1,
                        DirectNormalUserToVIPRate = 0.04,
                        DirectNormalUserToSuperVIPRate = 0.08,
                        DirectVIPGroupUserToSuperVIPRate = 0.04,
                        DirectSuperVIPUserToSuperVIPRate = 0.05,
                        DirectSuperVIPUserToVIPRate = 0.05,
                        DirectSuperVIPUserToNormalUserRate = 0.05
                    });
                }
                _context.SaveChanges();
            }
        }
    }
}
